package com.itheima.collection;

import java.util.ArrayList;
import java.util.Iterator;

public class CollectionDemo4 {
    public static void main(String[] args) {
        ArrayList<Student> stu = new ArrayList<Student>();
        Student stu1 = new Student("张三",23);
        Student stu2 = new Student("李四",24);
        Student stu3 = new Student("王五",25);
        stu.add(stu1);
        stu.add(stu2);
        stu.add(stu3);

        Iterator<Student> it = stu.iterator();
        while(it.hasNext()){
            Student s = it.next();
            System.out.println(s);
        }
        System.out.println("------------");

        for (Student student : stu) {
            System.out.println(student);
        }
        System.out.println("------------");

        stu.forEach(s-> System.out.println(s));
    }
}
class Student{
    private String name;
    private int age;

    public Student() {
    }

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}